package org.jeik.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 *
 * @author AAsha
 */
public abstract class DateUtilities {

    public static final int DAY_ONE = 1;

    /**
     * Sets the time portion of the passed date to be equal to the start of the
     * day (00:00:00).
     *
     * @param date Date object which time portion will be cleared
     * @param locale Locale object represents the locale to be used with the
     * dates
     * @return Date object represents the same date as the passed one with the
     * time portion cleared (00:00:00)
     * @throws IllegalArgumentException if either <code>date</code>
     * or <code>locale</code> is null
     */
    public static Date adjustTimeToStartOfDay(Date date, Locale locale) {
        if (date == null) {
            throw new IllegalArgumentException("date is null");
        }
        if (locale == null) {
            throw new IllegalArgumentException("locale is null");
        }

        Calendar nowCalendar = Calendar.getInstance(locale);
        nowCalendar.setTime(date);
        nowCalendar.set(nowCalendar.get(Calendar.YEAR),
                nowCalendar.get(Calendar.MONTH),
                nowCalendar.get(Calendar.DATE), 0, 0, 0);
        nowCalendar.set(Calendar.HOUR_OF_DAY, 0);
        nowCalendar.set(Calendar.MILLISECOND, 0);
        return nowCalendar.getTime();
    }

    /**
     * This method will return the java.util.Date with todays date
     *
     * @return Today
     * @since
     */
    public static Date getToday() {
        Calendar calendar = Calendar.getInstance();
        return calendar.getTime();
    }

    /**
     *
     * @param date
     * @return String dd/MM/yyyy
     */
    public static String getSimpleDate(Date date) {
        SimpleDateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
        return dateFormatter.format(date);
    }
}